#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020/6/16 0016 22:22
# @Author  : wzy
# @Site    : 
# @File    : operate_config.py
# @Software: PyCharm
from Util.operate_pathUrll import pathinfo
import configparser
config_url = pathinfo.get_config_fileUrl()

class operate_config:
    def load_ini(self):
        '''
        :return: 读取配置文件
        '''
        cf = configparser.ConfigParser()
        # 读取配置文件
        cf.read(config_url, encoding="utf-8-sig")
        return cf

    def get_config_value(self, key, section=None):
        '''
        预置条件 【server】
                host：127.0.0.1
        :param key: 对应host
        :param section:对应[server]
        :return: 返回 host：对应127.0.0.1
        '''
        if section == None:
            section = 'server'
        cf = self.load_ini()
        try:
            # 获取section下key对应的value
            data = cf.get(section, key)
        except Exception:
            print("没有获取到值")
            data = None
        return data


ope_config = operate_config()
if __name__ == "__main__":
    print(ope_config.get_config_value('host','server'))